﻿/*
 * Authors:
 *   钟峰(Popeye Zhong) <9555843@qq.com>
 *
 * Copyright (c) 2017 Flagwind Game Studio. All rights reserved.
 */

using System;
using System.Collections.Generic;

namespace Flagwind.Gaming
{
	/// <summary>
	/// 表示扑克牌的扩展方法类。
	/// </summary>
    public static class PokerExtension
    {
		/// <summary>
		/// 将字节类型的数值转换成对应的扑克牌。
		/// </summary>
		/// <param name="value">待转换的字节类型的数值。</param>
		/// <returns>返回转换后的扑克牌结构值。</returns>
		public static Poker ToPoker(this byte value)
		{
			return new Poker(value);
		}

		/// <summary>
		/// 将字节数值转换成对应的扑克牌数组。
		/// </summary>
		/// <param name="values">待转换的字节数组。</param>
		/// <returns>返回转换后的扑克牌结构数组。</returns>
		public static Poker[] ToPokers(this byte[] values)
		{
			if(values == null)
				return null;

			var pokers = new Poker[values.Length];

			for(var i = 0; i < values.Length; i++)
			{
				pokers[i] = new Poker(values[i]);
			}

			return pokers;
		}

		/// <summary>
		/// 将字节集转换成对应的扑克牌集。
		/// </summary>
		/// <param name="values">待转换的字节集。</param>
		/// <returns>返回转换后的扑克牌结构集。</returns>
		public static IEnumerable<Poker> ToPokers(this IEnumerable<byte> values)
		{
			if(values == null)
				yield break;

			foreach(var value in values)
			{
				yield return new Poker(value);
			}
		}
    }
}
